package com.geek.rest;



import com.geek.TypeUtils;

import javax.ws.rs.core.UriBuilder;
import java.lang.annotation.Annotation;
import java.util.List;


public interface UriAssembler<A extends Annotation> {

    default void assembler(UriBuilder uriBuilder, RequestTemplate requestTemplate, Object[] args) {
        Class<A> annotationType = getAnnotationType();
        if (annotationType == null) {
            return ;
        }
        //获取该类对应的泛型类中  参数中使用到的元信息
        List<AnnotatedParamMetadata> paramMetadata = requestTemplate.getAnnotatedParamMetadata(annotationType);
        for (AnnotatedParamMetadata paramMetadatum : paramMetadata) {
            assembler(uriBuilder, paramMetadatum, args);
        }
    }


    void assembler(UriBuilder uriBuilder, AnnotatedParamMetadata metadata, Object[] args);




    /**
     * 获取反射对应的具体类
     * @return
     */
    default Class<A> getAnnotationType() {
        List<Class<?>> classes = TypeUtils.resolveTypeArguments(this.getClass());
        if (classes.isEmpty()) {
            return null;
        }
        return (Class<A>) classes.get(0);
    }


}
